using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Script.Serialization;

namespace CentralOffice.WebClient.CommonServices
{
    /// <summary>
    /// Summary description for EnterpriseNoticeService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    [ToolboxItem(false)]
    public class EnterpriseNoticeService : System.Web.Services.WebService
    {

        [WebMethod]
        public string BothBoundsRandoms(int seed, int lower, int upper)
        {
            string[] ss = new string[100];
            //unchecked((int)DateTime.Now.Ticks)
            Random randObj = new Random();
            for (int j = 0; j < 100; j++)
            {
                //Random randObj = new Random(seed);

                //ss[j] = randObj.Next(lower, upper).ToString();

                ss[j] = randObj.Next(lower, upper).ToString();
            }
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            return javaScriptSerializer.Serialize(ss);
        }

        [WebMethod]
        public int GetLatestNumberOfNotices()
        {
            int numberOfNotices = 0;

            //using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings[0].ConnectionString))
            //{
            //    using (SqlCommand cmd = new SqlCommand("GetLatestNumberOfEmails", conn))
            //    {
            //        cmd.CommandType = CommandType.StoredProcedure;

            //        conn.Open();
            //        numberOfEmails = (int)cmd.ExecuteScalar();
            //    }
            //}
            Guid enterprise = ApplicationContext.EnterpriseId;
            if (enterprise != Guid.Empty)
            {
                numberOfNotices = CentralOffice.Enterprise.BusinessActions.NoticeReceiver.FetchNoticeCountByEnterpriseId(enterprise, false);
            }

            //Random random = new Random();

            //numberOfNotices = random.Next(10, 10000);

            return numberOfNotices;
        }

        [WebMethod]
        public int GetLatestNumberOfSms()
        {
            //int numberOfSms = 0;

            //Guid userId = ApplicationContext.ActualUserId;
            //if (userId != Guid.Empty)
            //{
            //    numberOfSms = 
            //}

            int numberOfSms = 0;
            numberOfSms = CentralOffice.MyTable.BusinessActions.ViewSms.GetCount(" ToId='" + ApplicationContext.ActualUserId.ToString().Trim() + "' and RemindFlag='0' and DeleteFlag='0'", false);

            return numberOfSms;
        }


    }
}
